DISCUSSION
The
ATSUMeasureTextImage function obtains the standard bounding rectangle, or image bounds, of a line of text.
ATSUMeasureTextImage takes into account line rotation, alignment, and justification, as well as other characteristics that affect layout like hanging punctuation. The rectangle passed back in
oTextImageRect is the same one used by the function
ATSUDrawText to draw a line of text.
The standard bounding rectangle is the smallest rectangle that completely encloses the filled or framed parts of the line. While the typographic bounding rectangle takes into account the ascent and descent lines for the displayed glyphs, the standard bounding rectangle just encloses the "inked parts" of the displayed glyphs.
To obtain the typographic bounds of a line after it is laid out, call the function
ATSUGetGlyphBounds. To calculate the typographic bounds of a line before it is laid out, call the function
ATSUMeasureText.
If you want to instead obtain the typographic bounds of a final laid-out line, call the function
ATSUGetGlyphBounds. To calculate the standard bounding rectangle around a final laid-out line, call the function
ATSUMeasureTextImage. For an illustration of the difference between a standard and typographic bounding rectangle, see
Figure 2-1.
Before calculating the standard bounding rectangle enclosing a range of text,
ATSUMeasureTextImage examines the text layout object to make sure that the style runs cover the entire range of text. If there are gaps between style runs,
ATSUMeasureTextImage assigns the characters in the gap to the style run following the gap. If there is no style run at the beginning of the range of text,
ATSUMeasureTextImage assigns these characters to the first style run it can find. If there no style run at the end of the range of text,
ATSUMeasureTextImage assigns the remaining characters to the last style run it can find.
The height of the standard bounding rectangle is determined by the natural line ascent and descent calculated for the line.
ATSUMeasureTextImage ignores the previously set line ascent and descent values for the line it is measuring. However, it uses other text layout attributes set for the line determine character layout. If no attributes have been set for the line,
ATSUMeasureTextImage uses attributes set for the text layout object.
If the line is rotated, the sides of the passed back rectangle are parallel to the coordinate axes and encompass the rotated line. You should pass the standard bounding rectangle of a line of text to the function
EraseRect to ensure erase all the text. In contrast, the typographic bounding rectangle passed back by
ATSUMeasureText reflects an unrotated line.
The coordinates you specify in
iLocationX and
iLocationY are the same values used by
ATSUDrawText for the line of text to be measured.